<template>
  <div class="app">
    <div v-if="!isReady" class="loading-overlay">
      <div class="loading-spinner"></div>
    </div>
    <TheHeader v-show="isReady" />
    <main v-show="isReady" class="main-content">
      <router-view></router-view>
    </main>
    <TheFooter v-show="isReady" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useArticleStore } from './stores/articleStore'
import { useUserStore } from './stores/userStore'
import TheHeader from './components/TheHeader.vue'
import NavMenu from './components/NavMenu.vue'
import BlogList from './components/BlogList.vue'
import TheFooter from './components/TheFooter.vue'

const articleStore = useArticleStore()
const userStore = useUserStore()
const isReady = ref(false)

onMounted(async () => {
  try {
    await userStore.initializeAuth()
    await articleStore.fetchArticles()
    isReady.value = true
    if(userStore.isLogin){
      userStore.fetchUserAllActivities(userStore.currentUser.id)
    }
  } catch (error) {
    console.error('初始化数据失败:', error)
  }
})
</script>

<style scoped>
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding: 24px 0;
  background: var(--bg-color);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
  }
  
  .left-sidebar {
    display: none;
  }
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style> 